/*
 * Author: vdaras
 */

#ifndef BUTTON_H
#define	BUTTON_H


#include "../sdl/Canvas.h"
#include "../sdl/Color.h"
#include "../sdl/Font.h"
#include "../Resource.h"
#include "AbstractButton.h"
#if defined(_MSC_VER)
#include <memory>
#else
#include <auto_ptr.h>
#endif

namespace gui
{

/**
 * Simple button rendered using SDL Canvases for it's display part.
 */

class Button : public AbstractButton
{
    const static int BACKGROUND = 0;
    const static int FOREGROUND = 1;

private:
    std::string m_caption;
    sdl::Color m_colors[3][2];
    std::auto_ptr< sdl::Canvas > m_displays[3];
    Resource<sdl::Font> *m_fontRes;
    sdl::Font *m_font;
    
public:
    
   /**
    * Constructor initializes the Abstract Button parent and the caption of the button.
    * The display part of the button is initialized with the default colors.
    *
    * @param name: id of the Button Component
    * @param width: width of the Button Component
    * @param height: height of the Button Component
    * @param caption: the caption of the button
    */
    
    Button(const std::string &name, int width, int height, const std::string &caption, Resource<sdl::Font> *fnt);
    
    
   /**
    * Constructor initializes the Abstract Button parent and the caption of the button.
    * The display part of the button is initialized with the default colors.
    *
    * @param name: id of the Button Component
    * @param width: width of the Button Component
    * @param height of the Button Component
    * @Param caption: the caption of the button
    */
    
    Button(const std::string &name, Container *parent, int x, int y, int width, int height, const std::string &caption, Resource<sdl::Font> *fnt);
    
    
    virtual ~Button();

    
    /**
     * Resizes this Button.
     *
     * @param width: new width.
     * @param height: new height.
     */
    
    virtual void Resize(int width, int height);
    
    
   /**
    * Sets button's caption.
    *
    * @param caption: the desired caption
    */
    
    void SetCaption(const std::string &caption);
    
    
   /**
    * Sets the background color of the button.
    *
    * @param color: desired color
    */

    void SetBackgroundColor(const sdl::Color &color);
    
    
   /**
    * Sets the foreground color of the button.
    *
    * @param color: desired color
    */
    
    void SetForegroundColor(const sdl::Color &color);
    
    
   /**
    * Sets the background color of the button when it's highlighted.
    *
    * @param color: desired color
    */
    
    void SetHighlightBackgroundColor(const sdl::Color &color);
    
    
   /**
    * Sets the foreground color of the button when it's highlighted.
    *
    * @param color: desired color
    */
	
    void SetHighlightForegroundColor(const sdl::Color &color);
    
    
   /**
    * Sets the background color of the button when it's clicked.
    *
    * @param color: desired color
    */
    
    void SetClickedBackgroundColor(const sdl::Color &color);
    
    
   /**
    * Sets the foreground color of the button when it's clicked.
    *
    * @param color: desired color
    */
    
    void SetClickedForegroundColor(const sdl::Color &color);

    
   /**
    * Renders the button on a surface depending on its state.
    *
    * @param target: target surface.
    */
    
    virtual void Draw(sdl::Surface *target) const;
    
    
   /**
    * Updates the button.
    */
    
    virtual void Update();
    
    
private:
    bool CreateDisplays();
    
    bool Initialize();
};

};

#endif	/* BUTTON_H */

